/*
 *  AMPLogCenter.h
 *  AMPlugin
 *
 *  Created by Toan on 11/2/12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */
#include "AMPLogCenter.h"
#include <iostream>
#include "StringUtils.h"
#include "HTTPRequestHelper.h"
#include <string>
using namespace std;


/********************************************************************************************************************
 *****Function: DataLogCenter
 *****Creator:  Toan Nguyen
 *****IN: int IDPCode
 *****out: 
 *****Objective: detect response code and send to server
 ********************************************************************************************************************/
void AMPLogCenter::DataLogCenter(int IDPCode)
{
	string log_data;
	
	switch (IDPCode) {
		case AMPPLUGIN_COULDNT_CONNECT:
			log_data = "Plugin couldn't connect to the server";
			break;
			
		case AMPPLUGIN_COULDNT_RESOLVE_PROXY:
			log_data = "Network requires proxy authentication";
			break;
			
		case AMPPLUGIN_UPLOAD_FAILED:	
			log_data = "Plugin couldn't upload file to server";
			break;
			
		case AMPPLUGIN_WRITE_ERROR:	
			log_data = "Plugin failed to write log/setting file";
			break;
			
		case AMPPLUGIN_READ_ERROR:	
			log_data = "Plugin failed to read log/setting file";
			break;
			
		case AMPPLUGIN_OUT_OF_MEMORY:	
			log_data = "Memory cannot allocating to working";
			break;
			
		case AMPPLUGIN_OPERATION_TIMEOUTED:	
			log_data = "Timeout error";
			break;
			
		case AMPPLUGIN_HTTP_RANGE_ERROR:	
			log_data = "HTTP range error";
			break;
			
		case AMPPLUGIN_HTTP_POST_ERROR:	
			log_data = "Plugin failed to post method";
			break;
			
		case AMPPLUGIN_BAD_DOWNLOAD_RESUME:	
			log_data = "Plugin failed to resume download";
			break;
			
		case AMPPLUGIN_FILE_COULDNT_READ_FILE:	
			log_data = "Plugin failed to read file";
			break;
			
		case AMPPLUGIN_ABORTED_BY_CALLBACK:	
			log_data = "Plugin failed to callback again";
			break;
			
		case AMPPLUGIN_INTERFACE_FAILED:	
			log_data = "Plugin failed to call interface";
			break;
			
		case AMPPLUGIN_SEND_ERROR:	
			log_data = "Plugin failed to send commmander";
			break;
			
		case AMPPLUGIN_RECV_ERROR:	
			log_data = "Plugin failed to recieve commander";
			break;
			
		case AMPPLUGIN_LOGIN_DENIED:	
			log_data = "Plugin failed to login server";
			break;
			
		case AMPPLUGIN_COULDNT_PARSE_JSON:	
			log_data = "Plugin failed to parsing json";
			break;
			
		case AMPPLUGIN_COULDNT_EXPORT_JPG:	
			log_data = "Plugin failed to exporting jpeg image";
			break;
			
		case AMPPLUGIN_COULDNT_EXPORT_IDML:	
			log_data = "Plugin failed to exporting IDML";
			break;
			
		case AMPPLUGIN_COULDNT_IMPORT_IDML:	
			log_data = "Plugin failed to import IDML";
			break;
			
		case AMPPLUGIN_COULDNT_ASSIGN_NEW_IMAGE:	
			log_data = "Plugin failed to assign new image";
			break;
			
		case AMPPLUGIN_COULDNT_AUTHENTICATION:	
			log_data = "Plugin failed to authentication";
			break;
			
		case AMPPLUGIN_COULDNT_PROXY_LOGIN:	
			log_data = "Plugin failed to login through proxies setting";
			break;
			
		case AMPPLUGIN_COULDNT_PROXY_AUTHENTICATION:	
			log_data = "Plugin failed to authentication with proxy";
			break;
			
		case AMPPLUGIN_COULDNT_PROXY_CONNECTION:	
			log_data = "Plugin couldn't connect to the server through proxy connection";
			break;
			
		case AMPPLUGIN_DOWNLOADING_FAILED:	
			log_data = "Plugin couldn't downloading file from server";
			break;
		
		case AMPPLUGIN_UNLOCK_PAGES_FAILED:	
			log_data = "Plugin couldn't unlock pages";
			break;
			
		case AMPPLUGIN_UNLOCK_STORY_FAILED:	
			log_data = "Plugin couldn't unlock story";
			break;
		
		case AMPPLUGIN_UPDATE_SESSION_FAILED:	
			log_data = "Plugin couldn't update session";
			break;
			
		case AMPPLUGIN_RENEW_SESSION_FAILED:	
			log_data = "Plugin couldn't renew session";
			break;
		
		case AMPPLUGIN_GET_PACKAGE_URL_FAILED:	
			log_data = "Couldn't get package form url";
			break;
		
		case AMPPLUGIN_GET_IMAGE_PREVIEW_DEFAULT_FAILED:	
			log_data = "Couldn't get preview image default form server";
			break;
		
		case AMPPLUGIN_CHECKOUT_FAILED:	
			log_data = "Couldn't checkout package form server";
			break;
			
		case AMPPLUGIN_SHOW_ISSUE_LIST_FAILED:	
			log_data = "Couldn't showing issue list form server";
			break;
			
		default:
			break;
	}
	
	string log_code;
	stringstream outstr;
	outstr << IDPCode;
	log_code = outstr.str();
	
	HTTPRequestHelper::CallLogCenter(log_data, log_code);
}